<?php
$response=array();
//input is soban by GET method
if(isset($_GET['soban']))
{
	$soban=$_GET['soban'];
}
else
{
	$response["success"]=0;
	$response["errorcode"]="field require is missing";
}

require_once('db_config.php');
/* Open a connection */
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);

$query="select * from bkxuatban where soban=$soban and trangthai!=3";
if($record=$mysqli->query($query))
{
	$response['success']=1;
	$response['xuatbans']=array();

	while ($row =$record->fetch_assoc()) 
	{
		$xb=array();
		$xb['mact']=$row['mact'];
		$xb['ngayct']=$row['ngayct'];
		$xb['soct']=$row['soct'];
		$xb['makhach']=$row['makhach'];
		$xb['giatri']=$row['giatri'];
		$xb['chietkhau']=$row['chietkhau'];
		$xb['sohd']=$row['sohd'];
		$xb['ngayhd']=$row['ngayhd'];
		$xb['giatrithue']=$row['giatrithue'];
		$xb['phiphucvu']=$row['phiphucvu'];
		$xb['giolapbill']=$row['giolapbill'];
		$xb['soban']=$row['soban'];
		$xb['sokhach']=$row['sokhach'];
		$xb['calamviec']=$row['calamviec'];
		$xb['trangthai']=$row['trangthai'];
		$xb['mapc']=$row['mapc'];
		$xb['hinhthuctt']=$row['hinhthuctt'];
		$xb['update']=$row['update'];
		$xb['gioketthuc']=$row['gioketthuc'];
		$xb['sothe']=$row['sothe'];
		$xb['billdup']=$row['billdup'];

		//get ds mat hang ban 
		$mact=$row['mact'];

		$query1="SELECT chitietban.id,chitietban.mahang,demohangban.tenhang,dongia1,dongia2,dongia3,soluong
                 FROM chitietban
                 JOIN demohangban ON chitietban.mahang=demohangban.mahang
                 where mact=$mact";

		if ($chitietban=$mysqli->query($query1)) 
		{
			$xb['chitietbans']=array();
			while ($ct=$chitietban->fetch_assoc()) 
			{
				$ctb=array();
				$ctb['id']=$ct['id'];
				//$ctb['mact']=$ct['mact'];
				$ctb['mahang']=$ct['mahang'];
				$ctb['soluong']=$ct['soluong'];
				//$ctb['chietkhau']=$ct['chietkhau'];
				//$ctb['giatri']=$ct['giatri'];
				//$ctb['update']=$ct['update'];
				//$ctb['trangthai']=$ct['trangthai'];
				//$ctb['soorder']=$ct['soorder'];
				//$ctb['gioorder']=$ct['gioorder'];
				//$ctb['phucvu']=$ct['phucvu'];
				//$ctb['tenhang']=$ct['tenhang'];
				//$ctb['tendonvi']=$ct['tendonvi'];
				//$ctb['ghichu']=$ct['ghichu'];
                $ctb['tenhang']=$ct['tenhang'];
                $ctb['dongia1']=$ct['dongia1'];
                $ctb['dongia2']=$ct['dongia2'];
                $ctb['dongia3']=$ct['dongia3'];

				array_push($xb['chitietbans'], $ctb);
			}
			$chitietban->close();
		}
		array_push($response['xuatbans'], $xb);		
	}
	$record->close();

	$mysqli->close();

}
echo json_encode($response);
?>